package com.twu.biblioteca.options;

import com.twu.biblioteca.streams.AppOutputStream;
import com.twu.biblioteca.streams.UserInputStream;
import com.twu.biblioteca.library.Library;

import java.io.IOException;
import java.io.OutputStream;

public class ReserveBook implements Option {

    @Override
    public void execute() throws IOException {
        AppOutputStream.writeLine("Input the book's ISBN to reserve:\n");
        String ISBN = getUserInputISBN();
        reserveBook(ISBN);
    }

    @Override
    public String toString() {
        return "Reserve Book";
    }

    private String getUserInputISBN() throws IOException {
        return UserInputStream.readLine();
    }

    private void reserveBook(String ISBN) throws IOException {
        boolean reserveResult = Library.getLibrary().reserveBook(ISBN);
        if (reserveResult) {
            AppOutputStream.writeLine("Thank You! Enjoy the book.\n");
        } else {
            AppOutputStream.writeLine("Sorry we don't have that book yet.\n");
        }
    }
}
